package com.heima.controller;

import com.heima.common.Result;
import com.heima.domain.dto.SkuClassDto;
import com.heima.domain.vo.SkuClassVo;
import com.heima.service.SkuClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vm-service/skuClass")
@Api(tags = "商品分类")
public class SkuClassController {

    @Autowired
    private SkuClassService skuClassService;

    @PostMapping
    @ApiOperation("添加商品分类")
    public Boolean addSort(@RequestBody SkuClassDto dto){
        Boolean flag = skuClassService.addSort(dto);
        return flag;
    }

    @GetMapping("/search")
    @ApiOperation("商品分类搜索")
    public Result getByPage(@RequestParam(required = false,defaultValue = "1") Integer pageIndex,
                            @RequestParam(required = false,defaultValue = "10") Integer pageSize,
                            @RequestParam(required = false) String className){
        return skuClassService.getByPage(pageIndex,pageSize,className);
    }

    @PutMapping("/{classId}")
    @ApiOperation("修改商品分类")
    public Boolean updateSku(@PathVariable String classId,@RequestBody SkuClassDto dto){
        Boolean flag = skuClassService.updateSku(classId,dto);
        return flag;
    }

    @GetMapping("/{classId}")
    @ApiOperation("获取分类信息")
    public SkuClassVo getSkuClassById(@PathVariable Integer classId){
        SkuClassVo vo = skuClassService.getSkuClassById(classId);
        return vo;
    }

    @DeleteMapping("/{classId}")
    @ApiOperation("删除商品分类")
    public void deleteSkuClassById(@PathVariable Integer classId){
        skuClassService.deleteSkuClassById(classId);
    }

}
